/**
 * 给定一个字符串，请你找出其中重复的 最长子串 的长度(直接拓展)。
 */
class Solution {

    public static void main(String[] args) {
        System.out.println(Solution.lengthOfLongestSubstring("aaaabbcc"));
    }

    public static int lengthOfLongestSubstring(String s) {
        int x = 1;
        for (int i = 1; i < s.length() - 1; i++) {
            int y = findSame(s.substring(i).toCharArray(), s.substring(0, s.length() - i).toCharArray());
            if (x < y) {
                x = y;
            }
        }
        return x;
    }

    public static int findSame(char[] chars1, char[] chars2) {
        int num = 0;
        int max = 0;
        for (int i = 0; i < chars1.length; i++) {
            if (chars1[i] == chars2[i]) {
                num++;
                if (num > max) {
                    max = num;
                }
            } else {
                num = 0;
            }
        }
        return max;
    }
}